﻿using System;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using System.Collections.ObjectModel;

namespace cz.uhul.DSMLv2
{



  /// <summary>
  /// LogicalOp = DSML FilterSet, can contain more than one entry from each LogicalOp
  /// </summary>
  [XmlInclude(typeof(AndOp))]
  [XmlInclude(typeof(OrOp))]
  [XmlInclude(typeof(NotOp))]
  [XmlInclude(typeof(PresentOp))]
  [XmlInclude(typeof(SubstringsOp))]
  [XmlInclude(typeof(EqualityMatchOp))]
  public class LogicalOp : FilterOp
  {


    public LogicalOp()
      : base()
    { }




    [XmlElement(ElementName = "and", Form = XmlSchemaForm.None, IsNullable = true, Type = typeof(AndOp))]
    public ObservableCollection<FilterOp> Ands { get; set; }




    [XmlElement(ElementName = "or", Form = XmlSchemaForm.None, IsNullable = true, Type = typeof(OrOp))]
    public ObservableCollection<FilterOp> Ors { get; set; }




    [XmlElement(ElementName = "not", Form = XmlSchemaForm.None, IsNullable = true, Type = typeof(NotOp))]
    public ObservableCollection<FilterOp> Nots { get; set; }




    [XmlElement(ElementName = "present", Form = XmlSchemaForm.None, IsNullable = true, Type = typeof(PresentOp))]
    public ObservableCollection<FilterOp> Presents { get; set; }




    [XmlElement(ElementName = "substrings", Form = XmlSchemaForm.None, IsNullable = true, Type = typeof(SubstringsOp))]
    public ObservableCollection<FilterOp> Substrings { get; set; }




    [XmlElement(ElementName = "equalityMatch", Form = XmlSchemaForm.None, IsNullable = true, Type = typeof(EqualityMatchOp))]
    public ObservableCollection<FilterOp> EqualityMatches { get; set; }




    [XmlIgnore]
    public ObservableCollection<FilterOp> Operations
    {
      get
      {
        ObservableCollection<FilterOp> tmp = new ObservableCollection<FilterOp>();

        if (this.Ands != null)
          foreach (AndOp op in this.Ands)
            tmp.Add(op);

        if (this.Ors != null)
          foreach (OrOp op in this.Ors)
            tmp.Add(op);

        if (this.Nots != null)
          foreach (NotOp op in this.Nots)
            tmp.Add(op);

        if (this.Presents != null)
          foreach (PresentOp op in this.Presents)
            tmp.Add(op);

        if (this.Substrings != null)
          foreach (SubstringsOp op in this.Substrings)
            tmp.Add(op);

        if (this.EqualityMatches != null)
          foreach (EqualityMatchOp op in this.EqualityMatches)
            tmp.Add(op);

        return tmp;
      }

    }

  }

}
